/**
 * Copyright © 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.test.handlingcases.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.test.handlingcases.entity.YjyShouji;
import com.jeeplus.modules.test.handlingcases.mapper.YjyShoujiMapper;
import com.jeeplus.modules.test.handlingcases.entity.YjyFueleven;
import com.jeeplus.modules.test.handlingcases.mapper.YjyFuelevenMapper;
import com.jeeplus.modules.test.handlingcases.entity.YjyFuFive;
import com.jeeplus.modules.test.handlingcases.mapper.YjyFuFiveMapper;
import com.jeeplus.modules.test.handlingcases.entity.YjyFuFour;
import com.jeeplus.modules.test.handlingcases.mapper.YjyFuFourMapper;
import com.jeeplus.modules.test.handlingcases.entity.YjyFuJk;
import com.jeeplus.modules.test.handlingcases.mapper.YjyFuJkMapper;
import com.jeeplus.modules.test.handlingcases.entity.YjyFuOne;
import com.jeeplus.modules.test.handlingcases.mapper.YjyFuOneMapper;
import com.jeeplus.modules.test.handlingcases.entity.YjyFuss;
import com.jeeplus.modules.test.handlingcases.mapper.YjyFussMapper;
import com.jeeplus.modules.test.handlingcases.entity.YjyFuTwo;
import com.jeeplus.modules.test.handlingcases.mapper.YjyFuTwoMapper;
import com.jeeplus.modules.test.handlingcases.entity.YjyThirteen;
import com.jeeplus.modules.test.handlingcases.mapper.YjyThirteenMapper;
import com.jeeplus.modules.test.handlingcases.entity.YjyFuThree;
import com.jeeplus.modules.test.handlingcases.mapper.YjyFuThreeMapper;
import com.jeeplus.modules.test.handlingcases.entity.YjyLast;
import com.jeeplus.modules.test.handlingcases.mapper.YjyLastMapper;
import com.jeeplus.modules.test.handlingcases.entity.YjyRecover;
import com.jeeplus.modules.test.handlingcases.mapper.YjyRecoverMapper;

/**
 * 1Service
 * @author 刘高峰
 * @version 2020-09-25
 */
@Service
@Transactional(readOnly = true)
public class YjyShoujiService extends CrudService<YjyShoujiMapper, YjyShouji> {

	@Autowired
	private YjyFuelevenMapper yjyFuelevenMapper;
	@Autowired
	private YjyFuFiveMapper yjyFuFiveMapper;
	@Autowired
	private YjyFuFourMapper yjyFuFourMapper;
	@Autowired
	private YjyFuJkMapper yjyFuJkMapper;
	@Autowired
	private YjyFuOneMapper yjyFuOneMapper;
	@Autowired
	private YjyFussMapper yjyFussMapper;
	@Autowired
	private YjyFuTwoMapper yjyFuTwoMapper;
	@Autowired
	private YjyThirteenMapper yjyThirteenMapper;
	@Autowired
	private YjyFuThreeMapper yjyFuThreeMapper;
	@Autowired
	private YjyLastMapper yjyLastMapper;
	@Autowired
	private YjyRecoverMapper yjyRecoverMapper;

	public YjyShouji get(String id) {
		YjyShouji yjyShouji = super.get(id);
		yjyShouji.setYjyFuelevenList(yjyFuelevenMapper.findList(new YjyFueleven(yjyShouji)));
		yjyShouji.setYjyFuFiveList(yjyFuFiveMapper.findList(new YjyFuFive(yjyShouji)));
		yjyShouji.setYjyFuFourList(yjyFuFourMapper.findList(new YjyFuFour(yjyShouji)));
		yjyShouji.setYjyFuJkList(yjyFuJkMapper.findList(new YjyFuJk(yjyShouji)));
		yjyShouji.setYjyFuOneList(yjyFuOneMapper.findList(new YjyFuOne(yjyShouji)));
		yjyShouji.setYjyFussList(yjyFussMapper.findList(new YjyFuss(yjyShouji)));
		yjyShouji.setYjyFuTwoList(yjyFuTwoMapper.findList(new YjyFuTwo(yjyShouji)));
		yjyShouji.setYjyThirteenList(yjyThirteenMapper.findList(new YjyThirteen(yjyShouji)));
		yjyShouji.setYjyFuThreeList(yjyFuThreeMapper.findList(new YjyFuThree(yjyShouji)));
		yjyShouji.setYjyLastList(yjyLastMapper.findList(new YjyLast(yjyShouji)));
		yjyShouji.setYjyRecoverList(yjyRecoverMapper.findList(new YjyRecover(yjyShouji)));
		return yjyShouji;
	}

	public List<YjyShouji> findList(YjyShouji yjyShouji) {
		return super.findList(yjyShouji);
	}

	public Page<YjyShouji> findPage(Page<YjyShouji> page, YjyShouji yjyShouji) {
		return super.findPage(page, yjyShouji);
	}

	@Transactional(readOnly = false)
	public void save(YjyShouji yjyShouji) {
		super.save(yjyShouji);
		for (YjyFueleven yjyFueleven : yjyShouji.getYjyFuelevenList()){
			if (yjyFueleven.getId() == null){
				continue;
			}
			if (YjyFueleven.DEL_FLAG_NORMAL.equals(yjyFueleven.getDelFlag())){
				if (StringUtils.isBlank(yjyFueleven.getId())){
					yjyFueleven.setTestDataMain(yjyShouji);
					yjyFueleven.preInsert();
					yjyFuelevenMapper.insert(yjyFueleven);
				}else{
					yjyFueleven.preUpdate();
					yjyFuelevenMapper.update(yjyFueleven);
				}
			}else{
				yjyFuelevenMapper.delete(yjyFueleven);
			}
		}
		for (YjyFuFive yjyFuFive : yjyShouji.getYjyFuFiveList()){
			if (yjyFuFive.getId() == null){
				continue;
			}
			if (YjyFuFive.DEL_FLAG_NORMAL.equals(yjyFuFive.getDelFlag())){
				if (StringUtils.isBlank(yjyFuFive.getId())){
					yjyFuFive.setTestDataMain(yjyShouji);
					yjyFuFive.preInsert();
					yjyFuFiveMapper.insert(yjyFuFive);
				}else{
					yjyFuFive.preUpdate();
					yjyFuFiveMapper.update(yjyFuFive);
				}
			}else{
				yjyFuFiveMapper.delete(yjyFuFive);
			}
		}
		for (YjyFuFour yjyFuFour : yjyShouji.getYjyFuFourList()){
			if (yjyFuFour.getId() == null){
				continue;
			}
			if (YjyFuFour.DEL_FLAG_NORMAL.equals(yjyFuFour.getDelFlag())){
				if (StringUtils.isBlank(yjyFuFour.getId())){
					yjyFuFour.setTestDataMain(yjyShouji);
					yjyFuFour.preInsert();
					yjyFuFourMapper.insert(yjyFuFour);
				}else{
					yjyFuFour.preUpdate();
					yjyFuFourMapper.update(yjyFuFour);
				}
			}else{
				yjyFuFourMapper.delete(yjyFuFour);
			}
		}
		for (YjyFuJk yjyFuJk : yjyShouji.getYjyFuJkList()){
			if (yjyFuJk.getId() == null){
				continue;
			}
			if (YjyFuJk.DEL_FLAG_NORMAL.equals(yjyFuJk.getDelFlag())){
				if (StringUtils.isBlank(yjyFuJk.getId())){
					yjyFuJk.setTestDataMain(yjyShouji);
					yjyFuJk.preInsert();
					yjyFuJkMapper.insert(yjyFuJk);
				}else{
					yjyFuJk.preUpdate();
					yjyFuJkMapper.update(yjyFuJk);
				}
			}else{
				yjyFuJkMapper.delete(yjyFuJk);
			}
		}
		for (YjyFuOne yjyFuOne : yjyShouji.getYjyFuOneList()){
			if (yjyFuOne.getId() == null){
				continue;
			}
			if (YjyFuOne.DEL_FLAG_NORMAL.equals(yjyFuOne.getDelFlag())){
				if (StringUtils.isBlank(yjyFuOne.getId())){
					yjyFuOne.setTestDataMain(yjyShouji);
					yjyFuOne.preInsert();
					yjyFuOneMapper.insert(yjyFuOne);
				}else{
					yjyFuOne.preUpdate();
					yjyFuOneMapper.update(yjyFuOne);
				}
			}else{
				yjyFuOneMapper.delete(yjyFuOne);
			}
		}
		for (YjyFuss yjyFuss : yjyShouji.getYjyFussList()){
			if (yjyFuss.getId() == null){
				continue;
			}
			if (YjyFuss.DEL_FLAG_NORMAL.equals(yjyFuss.getDelFlag())){
				if (StringUtils.isBlank(yjyFuss.getId())){
					yjyFuss.setTestDataMain(yjyShouji);
					yjyFuss.preInsert();
					yjyFussMapper.insert(yjyFuss);
				}else{
					yjyFuss.preUpdate();
					yjyFussMapper.update(yjyFuss);
				}
			}else{
				yjyFussMapper.delete(yjyFuss);
			}
		}
		for (YjyFuTwo yjyFuTwo : yjyShouji.getYjyFuTwoList()){
			if (yjyFuTwo.getId() == null){
				continue;
			}
			if (YjyFuTwo.DEL_FLAG_NORMAL.equals(yjyFuTwo.getDelFlag())){
				if (StringUtils.isBlank(yjyFuTwo.getId())){
					yjyFuTwo.setTestDataMain(yjyShouji);
					yjyFuTwo.preInsert();
					yjyFuTwoMapper.insert(yjyFuTwo);
				}else{
					yjyFuTwo.preUpdate();
					yjyFuTwoMapper.update(yjyFuTwo);
				}
			}else{
				yjyFuTwoMapper.delete(yjyFuTwo);
			}
		}
		for (YjyThirteen yjyThirteen : yjyShouji.getYjyThirteenList()){
			if (yjyThirteen.getId() == null){
				continue;
			}
			if (YjyThirteen.DEL_FLAG_NORMAL.equals(yjyThirteen.getDelFlag())){
				if (StringUtils.isBlank(yjyThirteen.getId())){
					yjyThirteen.setTestDataMain(yjyShouji);
					yjyThirteen.preInsert();
					yjyThirteenMapper.insert(yjyThirteen);
				}else{
					yjyThirteen.preUpdate();
					yjyThirteenMapper.update(yjyThirteen);
				}
			}else{
				yjyThirteenMapper.delete(yjyThirteen);
			}
		}
		for (YjyFuThree yjyFuThree : yjyShouji.getYjyFuThreeList()){
			if (yjyFuThree.getId() == null){
				continue;
			}
			if (YjyFuThree.DEL_FLAG_NORMAL.equals(yjyFuThree.getDelFlag())){
				if (StringUtils.isBlank(yjyFuThree.getId())){
					yjyFuThree.setTestDataMain(yjyShouji);
					yjyFuThree.preInsert();
					yjyFuThreeMapper.insert(yjyFuThree);
				}else{
					yjyFuThree.preUpdate();
					yjyFuThreeMapper.update(yjyFuThree);
				}
			}else{
				yjyFuThreeMapper.delete(yjyFuThree);
			}
		}
		for (YjyLast yjyLast : yjyShouji.getYjyLastList()){
			if (yjyLast.getId() == null){
				continue;
			}
			if (YjyLast.DEL_FLAG_NORMAL.equals(yjyLast.getDelFlag())){
				if (StringUtils.isBlank(yjyLast.getId())){
					yjyLast.setTestDataMain(yjyShouji);
					yjyLast.preInsert();
					yjyLastMapper.insert(yjyLast);
				}else{
					yjyLast.preUpdate();
					yjyLastMapper.update(yjyLast);
				}
			}else{
				yjyLastMapper.delete(yjyLast);
			}
		}
		for (YjyRecover yjyRecover : yjyShouji.getYjyRecoverList()){
			if (yjyRecover.getId() == null){
				continue;
			}
			if (YjyRecover.DEL_FLAG_NORMAL.equals(yjyRecover.getDelFlag())){
				if (StringUtils.isBlank(yjyRecover.getId())){
					yjyRecover.setTestDataMain(yjyShouji);
					yjyRecover.preInsert();
					yjyRecoverMapper.insert(yjyRecover);
				}else{
					yjyRecover.preUpdate();
					yjyRecoverMapper.update(yjyRecover);
				}
			}else{
				yjyRecoverMapper.delete(yjyRecover);
			}
		}
	}

	@Transactional(readOnly = false)
	public void delete(YjyShouji yjyShouji) {
		super.delete(yjyShouji);
		yjyFuelevenMapper.delete(new YjyFueleven(yjyShouji));
		yjyFuFiveMapper.delete(new YjyFuFive(yjyShouji));
		yjyFuFourMapper.delete(new YjyFuFour(yjyShouji));
		yjyFuJkMapper.delete(new YjyFuJk(yjyShouji));
		yjyFuOneMapper.delete(new YjyFuOne(yjyShouji));
		yjyFussMapper.delete(new YjyFuss(yjyShouji));
		yjyFuTwoMapper.delete(new YjyFuTwo(yjyShouji));
		yjyThirteenMapper.delete(new YjyThirteen(yjyShouji));
		yjyFuThreeMapper.delete(new YjyFuThree(yjyShouji));
		yjyLastMapper.delete(new YjyLast(yjyShouji));
		yjyRecoverMapper.delete(new YjyRecover(yjyShouji));
	}

}